package com.mach.platform.components;

import com.mach.platform.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @Description:  定时任务
 * @Package: com.mach.platform.components
 * @time 2018/4/26 0026 14:46    张宏平测试
 */
@Slf4j
@Component
public class SchedulerJobs {

	@Autowired
	private SchdulerWorker worker;


//	@Scheduled(cron = "15 */1 * * * ?")
	public void pickUpMinuteDatas () {
		log.info("system time to pick up minute datas from TABLE iot_dev_data_win");
		DateTime currentDateTime = DateUtil.getCurrentDateTime();
		String nsTime = DateUtil.getYmdhmsByDatetimeMinInMinute(currentDateTime);
		String neTime = DateUtil.getYmdhmsByDatetimeMaxInMinute(currentDateTime);
		DateTime lastDateTime = DateUtil.getCurrentDateTime().minusMinutes(1);
		String sTime = DateUtil.getYmdhmsByDatetimeMinInMinute(lastDateTime);
		String eTime = DateUtil.getYmdhmsByDatetimeMaxInMinute(lastDateTime);
		worker.pickupDataForMinuteForm(sTime, eTime, nsTime, neTime);
	}

//	@Scheduled(cron = "40 15 */1 * * ?")
	public void pickUpHourDatas ( ) {
		log.info("system time to pick up hour datas from TABLE iot_dev_data_win");
		DateTime currentDateTime = DateUtil.getCurrentDateTime();
		String nsTime = DateUtil.getYmdhmsByDatetimeMinInHour(currentDateTime);
		String neTime = DateUtil.getYmdhmsByDatetimeMaxInHour(currentDateTime);
		DateTime lastDateTime = DateUtil.getCurrentDateTime().minusHours(1);
		String sTime = DateUtil.getYmdhmsByDatetimeMinInHour(lastDateTime);
		String eTime = DateUtil.getYmdhmsByDatetimeMaxInHour(lastDateTime);
		worker.pickupDataForHourForm(sTime, eTime, nsTime, neTime);
	}

}
